//
//  TopicDetailVC.m
//  A_Project_DLS151129_SQ
//
//  Created by 宋强 on 16/2/27.
//  Copyright © 2016年 www.lanou3g.com蓝鸥. All rights reserved.
//

#import "TopicDetailVC.h"

@interface TopicDetailVC ()<UIWebViewDelegate>
@property (nonatomic, retain)NSMutableArray *dataArr;
@end

@implementation TopicDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    //数据处理
    [self dataHandle];
}
- (void)dataHandle
{
    NSString *url = @"http://api2.pianke.me/group/posts_info";
    NSDictionary *dic = @{@"contentid": _contentId, @"client":@2};
    [PWNetWorking POSTWithURL:url body:dic completion:^(id result) {
        NSString *htmlStr = result[@"data"][@"postsinfo"][@"html"];
        CGFloat width = self.view.frame.size.width;
        NSString *newHtml = [NSString stringWithFormat:@"<head><style>img{max-width:%fpx !important;}</style></head>%@",width, htmlStr];
        //创建webView
        UIWebView *web = [[UIWebView alloc] initWithFrame:self.view.frame];
        web.delegate = self;
        //web.scalesPageToFit = YES;
        [web loadHTMLString:newHtml baseURL:nil];
        [self.view addSubview:web];
        [web release];
        }];

}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
    CGRect frame = webView.frame;
    webView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, height);
    NSLog(@"~~~~~~~%f",height);
    }
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
